package com.blockchain.front.servlets.financial;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.GdState;
import com.blockchain.framework.config.service.VariableManage;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.framework.service.exception.ParameterException;
import com.blockchain.front.service.common.entity.GdEntity;
import com.blockchain.front.service.financial.GdManage;
import com.blockchain.front.servlets.security.AbstractSceurityServlet;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;

public class UpdateGd extends AbstractSceurityServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		GdManage manage = serviceSession.getService(GdManage.class);
		GdEntity gdEntity = manage.get(id);
		if (id <= 0 || gdEntity.sellId != serviceSession.getSession().getAccountId()) {
			throw new ParameterException("该订单不是你的挂单");
		}
		GdEntity[] pdson = manage.getPdson(id);
		request.setAttribute("gdEntity", gdEntity);
		request.setAttribute("pdson", pdson);
		forwardView(request, response,UpdateGd.class);
	}

	@Override
	protected void processPost(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		GdState gdState = EnumParser.parse(GdState.class, request.getParameter("gdState"));
		GdManage manage = serviceSession.getService(GdManage.class);
		manage.updateGd(id,gdState,manage.get(id));
		sendRedirect(request, response, getController().getURI(request, Wygd.class));
	}

}